<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<?php if(isset($questions)): ?>
<script language="javascript" type="text/javascript">
	function dropdownlist(listindex) {
		document.inputform.subcategory.options.length = 0;
		switch (listindex) {
			<?php foreach($parents as $parent): ?>
				case "<?= $parent['question']; ?>" :
					document.inputform.subcategory.options[0]=new Option("Select Sub-Category","");
					<?php $i=1; ?>
					<?php foreach($questions[$parent['question_id']] as $question): ?>
						document.inputform.subcategory.options[<?= $i++; ?>]=new Option("<?= $question['question']; ?>","<?= $question['question_id']; ?>");
					<?php endforeach; ?>
				break;
			<?php endforeach; ?>
		} 
		return true;
	}
</script>
<? endif; ?>
</head>
<body>

<?php if(isset($ticket_id)): ?>
<h2>Ticket #<?= $ticket_id; ?></h2>
<h3>Ticket Status: <?= $currentTicket['state']; ?></h3>
<b>Creator:</b> <i><?= $currentTicket['creator']; ?> </i><br />
<b>Handler:</b> <i><?= $currentTicket['handler']; ?> </i><br />
<?php else: ?>
<h2>Create New Ticket</h2>
<?php endif; ?>

<form action="statusUpdate.php" name="inputform">
<?php if(isset($parents)): ?>
	<select name="category" id="category" onchange="dropdownlist(this.options[this.selectedIndex].value);">
		<option value="">--Select Type Of Ticket--</option>
		<?php foreach($parents as $parent): ?>
			<option value="<?= $parent['question']; ?>"><?= $parent['question']; ?></option>
		<?php endforeach; ?>
	</select>
	<script type="text/javascript" language="JavaScript">
		document.write('<select name="subcategory"><option value="">--Select Sub-Category--</option></select>');
	</script>
	<noscript><select name="subcateory" id="subcategory">
		<option value="">Select Sub-Category</option>
	</select></noscript>
<?php endif; ?>

<?php if(isset($authcode)): ?>
	<input type="hidden" name="authToken" value="<?= $authcode; ?>" />
<?php endif; ?>

<?php if(isset($ticket_id)): ?>
<h4>Message:</h4>
<div id="messageBox">
<?= $currentTicket['message']; ?>
</div>
<br />
<b>by</b> <i><?= $currentTicket['author']; ?></i> on <?= $currentTicket['timestamp']; ?><br />
<?php endif; ?>
<hr />
<?php if(isset($states)): ?>
	<select name="state">
		<option value="">--Set New Status--</option>
		<?php foreach( $states as $state ): ?>
			<option value="<?= $state; ?>"><?= $state; ?></option>
		<?php endforeach; ?>
	</select>
<?php else: ?>
	<input type="hidden" name="state" value="open" />
<?php endif; ?>
<br />
Please include a detailed message describing the problem or question. <br />
Make sure to include details about all error messages or exactly what you were doing when the problem or question occurred, if applicable.<br />
<textarea rows="10" cols="40" name="message"></textarea><br />
<?php if(!isset($ticket_id)): ?>
	Your email address: <input type="text" name="author"></input>
<?php else: ?>
	Your email address: <b><?= $user; ?></b><input type="hidden" name="author" value="<?= $user; ?>"></input>
<?php endif; ?>
<br /><input type="submit" ></input>
</form>

<?php // View Ticket History ?>
<?php if(isset($history)): ?>
<h2>View Ticket History</h2>
<table border="1">
<?php foreach( $history as $entry ): ?>
	<tr><th>Date: <?= $entry['date']; ?></th><th>State: <?= $entry['state']; ?></th><th>Author: <?= $entry['author']; ?></th></tr>
	<tr><th>Message</th></tr>
	<tr><td><?= $entry['message']; ?></th></tr>
<?php endforeach; ?>
</table>
<?php endif; ?>
<?php // end Ticket History ?>

</body>
</html>
